package com.online.shopping.controller;

import com.online.shopping.mapper.TbItemCatMapper;
import com.online.shopping.mapper.TbTypeTemplateMapper;
import com.online.shopping.pojo.TbItemCat;
import com.online.shopping.pojo.TbItemCatExample;
import com.online.shopping.pojo.TbTypeTemplate;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Rui
 * @version 1.0
 * @date 2020/11/23 14:58
 */
@RestController
@CrossOrigin
@Slf4j
@RequestMapping("/manager/itemCat")
public class ItemCatController {

    @Autowired
    private TbItemCatMapper itemCatMapper;
    @Autowired
    private TbTypeTemplateMapper typeTemplateMapper;

    @GetMapping("/findByParentId/{parentId}")
    private List<TbItemCat> findByParentId(@PathVariable("parentId") Long parentId){
        TbItemCatExample example = new TbItemCatExample();
        TbItemCatExample.Criteria criteria = example.createCriteria();
        criteria.andParentIdEqualTo(parentId);

        List<TbItemCat> tbItemCats = itemCatMapper.selectByExample(example);
        log.info(String.valueOf(tbItemCats));
        return tbItemCats;
    }

    @GetMapping("/findOne/{id}")
    public TbItemCat findOne(@PathVariable("id") Long id){
        TbItemCat tbItemCat = itemCatMapper.selectByPrimaryKey(id);
        log.info(String.valueOf(tbItemCat));
        return tbItemCat;
    }

    @GetMapping("/findAll")
    public List<TbItemCat> findAll(){
        List<TbItemCat> tbItemCatList = itemCatMapper.selectByExample(null);
        return tbItemCatList;
    }

}
